<?php

namespace App\Containers\AppSection\File\UI\API\Transformers;

use App\Containers\AppSection\Confirmation\UI\API\Transformers\ConfirmationTransformer;
use App\Containers\AppSection\File\Models\File;
use App\Containers\AppSection\Profile\UI\API\Transformers\ProfileTransformer;
use App\Containers\AppSection\Project\UI\API\Transformers\ProjectTransformer;
use App\Containers\AppSection\Signature\UI\API\Transformers\SignatureTransformer;
use App\Containers\AppSection\Type\UI\API\Transformers\TypeTransformer;
use App\Ship\Parents\Transformers\Transformer;
use League\Fractal\Resource\Item;

class FileTransformer extends Transformer
{
    protected array $defaultIncludes = [

    ];

    /**
     * @var  array
     */
    protected array $availableIncludes = [
        'profile',
        'project',
        'signature',
        'confirmation',
        'sign'
    ];

    public function transform(File $t): array
    {
        return [
            'object' => $t->getResourceKey(),
            'include' => $this->getAvailableIncludes(),
            'id' => $t->getHashedKey(),
            'name' => $t->name,
            'extension' => $t->extension,
            'size' => $t->size,
            'type' => $t->type,
            'sign_type' => $t->sign_type,
            'created_at' => $this->dateFormatter($t->created_at),
            'updated_at' => $this->dateFormatter($t->updated_at),
            'readable_created_at' => $t->created_at->diffForHumans(),
            'readable_updated_at' => $t->updated_at->diffForHumans()
        ];
    }

    public function includeProfile(File $t): ?Item
    {
        return $this->item($t->profile, new ProfileTransformer);
    }

    public function includeProject(File $t): ?Item
    {
        return $this->nullableItem($t->project, new ProjectTransformer);
    }

    public function includeSignature(File $t): ?Item
    {
        return $this->nullableItem($t->signature, new SignatureTransformer);
    }

    public function includeConfirmation(File $t): ?Item
    {
        return $this->nullableItem($t->confirmation, new ConfirmationTransformer);
    }

    public function includeSign(File $t): ?Item
    {
        return $this->nullableItem($t->sign, new TypeTransformer);
    }
}
